//显示数据条数
var pagesize =1000;
//当前数量
var curCount = 0;
//显示内容
var cid;
var objcontent;
var obj;
function init() {
	var Accordion = function(el, multiple) {
		this.el = el || {};
		this.multiple = multiple || false;

		// Variables privadas
		var links = this.el.find('.link');
		// Evento
		links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown)
	}

	Accordion.prototype.dropdown = function(e) {
		var $el = e.data.el;
			$this = $(this),
			$next = $this.next();

		$next.slideToggle();
		$this.parent().toggleClass('open');

		if (!e.data.multiple) {
			$el.find('.submenu').not($next).slideUp().parent().removeClass('open');
		};
	}	

	var accordion = new Accordion($('#accordion'), false);
}

$(document).ready(function(){
	goback("../main.html");
	obj=$('#accordion');
    var Post =basedata('gcotactsinfo');
    var num;
	ajaxcocRequest('../../../api/group/getgroupcontactlisttreedata', 'post', Post, function(msg){
		if(msg.code ==100){			
			var html="";
			var htmlchild="";
			if(msg["data"]!=null)
			{
				//console.log(JSON.stringify(msg["data"]));
			for(var i=0;i<msg["data"].length;i++){
				var thisItem=msg['data'][i];
				if(thisItem.n1!=null)
				{
					html+='<li> ';
					if(i==0)
						html+='<div class="link fontcolor18"><i class="fa fa-home fa-fw"></i>'+thisItem.n0+'<i class="fa fa-chevron-down"></i></div><ul class="submenu">';
					else
						html+='<div class="link fontcolor16"><i class="fa fa-plus fa-fw"></i>'+thisItem.n0+'<i class="fa fa-chevron-down"></i></div><ul class="submenu">';
						
					for(var j=0;j<thisItem.n1.length;j++)
					{
						var thisItemchild=thisItem.n1[j];
						var nextItemchild=thisItem.n1[j+1];
						num=thisItemchild.ids;
						if(thisItemchild.parentids==thisItem.n2)
						{
							if(nextItemchild!=null)
							{
								if(num==nextItemchild.parentids)
								{
									if(htmlchild!='')
										htmlchild+='</ul></div></li>';
										
									htmlchild+='<li> ';
									htmlchild+='<div class="link fontcolor14"><i class="fa fa-plus fa-fw"></i>'+thisItemchild.nodename+'<i class="fa fa-chevron-down"></i></div><ul class="submenu">';
									htmlchild += '<li>';
									// html += '<div class="jobTitle" data-value="'+num+'" onclick="rec('+num+')">';
									htmlchild += '<div class="jobTitleshi" data-value="'+nextItemchild.ids+'" onclick="rec(this);">';
									htmlchild += '<span style="color:black;">' + nextItemchild.nodename + '</span>';
									htmlchild += '<span style="position:absolute;right:2.5%;"><img src="../../image/home/conten/smallPeople.png"><span style="margin:0px 5px;font-size:16px;">' + nextItemchild.snum + "人" + '</span><img class="arrows" src="../../image/home/conten/downIcon.png"></span>';
									htmlchild += '</div><div class="11'+nextItemchild.ids+'" style="display:none;"></div></li>';
									
								}else{
									html += '<li>';
									// html += '<div class="jobTitle" data-value="'+num+'" onclick="rec('+num+')">';
									html += '<div class="jobTitle" data-value="'+num+'" onclick="rec(this);">';
									html += '<span style="color:black;">' + thisItemchild.nodename + '</span>';
									html += '<span style="position:absolute;right:2.5%;"><img src="../../image/home/conten/smallPeople.png"><span style="margin:0px 5px;font-size:16px;">' + thisItemchild.snum + "人" + '</span><img class="arrows" src="../../image/home/conten/downIcon.png"></span>';
									html += '</div><div class="11'+num+'" style="display:none;"></div></li>';
								}
							}else{
								html += '<li>';
								// html += '<div class="jobTitle" data-value="'+num+'" onclick="rec('+num+')">';
								html += '<div class="jobTitle" data-value="'+num+'" onclick="rec(this);">';
								html += '<span style="color:black;">' + thisItemchild.nodename + '</span>';
								html += '<span style="position:absolute;right:2.5%;"><img src="../../image/home/conten/smallPeople.png"><span style="margin:0px 5px;font-size:16px;">' + thisItemchild.snum + "人" + '</span><img class="arrows" src="../../image/home/conten/downIcon.png"></span>';
								html += '</div><div class="11'+num+'" style="display:none;"></div></li>';
							}
						}else if(nextItemchild!=null&&thisItemchild.parentids==nextItemchild.parentids)
						{
							htmlchild += '<li>';
							// html += '<div class="jobTitle" data-value="'+num+'" onclick="rec('+num+')">';
							htmlchild += '<div class="jobTitle" data-value="'+nextItemchild.ids+'" onclick="rec(this);">';
							htmlchild += '<span style="color:black;">' + nextItemchild.nodename + '</span>';
							htmlchild += '<span style="position:absolute;right:2.5%;"><img src="../../image/home/conten/smallPeople.png"><span style="margin:0px 5px;font-size:16px;">' + nextItemchild.snum + "人" + '</span><img class="arrows" src="../../image/home/conten/downIcon.png"></span>';
							htmlchild += '</div><div class="11'+nextItemchild.ids+'" style="display:none;"></div></li>';
						}
						
					}
					html+='</ul></div></li>';
				}else
				{
					html += '<li>';
					// html += '<div class="jobTitle" data-value="'+num+'" onclick="rec('+num+')">';
					html += '<div class="jobTitle" data-value="'+thisItem.n2+'" onclick="rec(this);">';
					html += '<span style="color:black;">' + thisItem.n0 + '</span>';
					html += '<span style="position:absolute;right:2.5%;"><img src="../../image/home/conten/smallPeople.png"><span style="margin:0px 5px;font-size:16px;">' + thisItem.snum + "人" + '</span><img class="arrows" src="../../image/home/conten/downIcon.png"></span>';
					html += '</div><div class="11'+thisItem.n2+'" style="display:none;"></div></li>';
				}
				htmlchild+='</ul></div></li>';
				html+=htmlchild;
				htmlchild='';
				//alert(JSON.stringify(msg["data"][0].n2))
			}
			
			obj.append(html);
			$(".tte").click(function(){
			    $(this).next().slideToggle();
			   
			});
			$(".tteshi").click(function(){
			    $(this).next().slideToggle();
			   
			});
			$(".ttexian").click(function(){
			    $(this).next().slideToggle();
			   
			});
			init();
			$("img").error(function(){
				$(this).attr("src","../../image/home/busess/yunzo_def.png")
			});
			}
				
	}
	else{
		$("body").append('<div class="wuwang"><img src="../../image/iconfont-wangluo.png"><p>网络拥堵，信息塞车</p></div>')
	}
	});
	
});
function rec(e){
	cid=$(e).attr('data-value');
	var $listDiv=$(".11"+cid);
	if($listDiv.css("display")=="none"){
		$listDiv.css("display","block");
		var parambody =basedata('gcotactsinfo')+"&curCount="+curCount+"&cid="+cid+"&pagesize="+pagesize;
		ajaxcocRequest('../../../api/group/getmemberinfolistbycid', 'post', parambody, function(msg){
			if(msg.code ==100){
				var html="";
				var userSrc;
				for(var i=0;i<msg['data'].length;i++){	
					var thisItem=msg['data'][i];
					if(thisItem!=null)
					{
						html += '<a tapmode="active" onclick="openNews(\'' + thisItem.n4 + '\');">'
						html += '<div class="logo">'
						if(thisItem.n1=="null"){
							userSrc="../../image/tongxunlu.png";
						}else{
							userSrc=thisItem.n1;
						};
						html += '<img class="userimgs" src="' + userSrc + '"/>'
						html += '</div>'
						html += '<div class="content">'
						html += '<h2 class="title">' + ($mtype=="guest"?thisItem.n2.substring(1,0)+"**":thisItem.n2) + '</h2>'
						html += '<p>' + thisItem.n3 + '</p>'
						html += '</div></a>';
					}
				}
				
				$(".11"+cid).append(html);
				$("img").error(function(){
					$(this).attr("src","../../image/home/busess/yunzo_def.png")
				})
			}
			else{
				$("body").append('<div class="wuwang"><img src="../../image/iconfont-wangluo.png"><p>网络拥堵，信息塞车</p></div>')
			}
		});
	}
	else{
		$(".11"+cid).css("display","none");
		$(".11"+cid).empty();
		//$("li div:eq(1)").css("display","none");
		//$("li div:eq(1)").empty();
	}
	
}
sTart_Stop();
function fuzzySearch(){
	var likevalue=$('#fuzzyText').val();
	obj.html("");
	var bodyParam = {"mid":$mid,"groupid":$groupid,"did":initdata.get('gcotactsinfo'),"type":0,"pagesize":pagesize,"curcount":curCount,"likevalue":likevalue};
	ajaxCoCRequest('../../../api/group/querybyvalueforgroupcontactlist', 'POST', bodyParam, function(msg) {
		if (msg.code==100) {				
			$('#fuzzyText').val("");
			var html = '';
			
			for (var i = 0; i < msg['data'].length; i++) {
				var thisItem = msg['data'][i];
				html += '<li>'
				html += '<div class="jobTitle">'
				html += '<span style="font-weight:600;">' + thisItem.n0 + '</span>'
				html += '<span style="position:absolute;right:2.5%;"><img src="../../image/icon/smallPeople.png"><span style="margin:0px 5px;font-size:20px;">' + thisItem.n5.length + "人" + '</span><img class="arrows" src="../../image/icon/downIcon.png"></span>'
				html += '</div>'
				html += '<div class="memberList" style="display:none;"><ul>'
				for (var j = 0; j < thisItem.n5.length; j++) {
					if(thisItem.n5[j].n1=="null"){
							userSrc="../../image/defaultImg2.png";
						}else{
							userSrc=thisItem.n5[j].n1;
						};
					html += '<li>'
					html += '<a tapmode="active" onclick="openNews(\'' + thisItem.n5[j].n4 + '\');">'
					html += '<div class="logo">'
					html += '<img class="userimgs" src="' + userSrc + '"/>'
					html += '</div>'
					html += '<div class="content">'
					html += '<h2 class="title">' + $mtype=="guest"?thisItem.n5[j].n2 .substring(1,0):thisItem.n5[j].n2 + '</h2>'
					html += '<p>' + thisItem.n5[j].n3 + '</p>'
					html += '</div></a>'
					html += '</li>'
				}
				html += '</ul></div>'
				html += '</li>'
			}
			
			obj.html(html);
			$("img").error(function(){
				$(this).attr("src","../../image/home/busess/yunzo_def.png")
			})
			var $memberMenu = $(".jobTitle");
			var $listDiv = $(".memberList");
			var $arrows = $(".arrows");
			$memberMenu.click(function() {
				var index = $memberMenu.index(this);
				if ($listDiv[index].style.display == "none") {
					$listDiv[index].style.display = "block";
					$arrows[index].src = "../../image/icon/upIcon.png";
				} else {
					$listDiv[index].style.display = "none"
					$arrows[index].src = "../../image/icon/downIcon.png";
				}
			});

		} else {
			$("body").append('<div class="wuwang"><img src="../../image/iconfont-wangluo.png"><p>网络拥堵，信息塞车</p></div>')
		}
	});
}
function openNews(infoid)
{	
	window.location='selfinfo.html'+'?infoid='+infoid;
}